package com.wangp.mywrite.s_netty.netty.ch3;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;

import static com.wangp.mywrite.s_netty.netty.ch3.TestByteBuf.log;

/**
 * @author tooStronger
 * @date 2023/3/19
 */
public class TestSlice {

    public static void main(String[] args) {
        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer(10);
        buffer.writeBytes(new byte[]{'a','b','c','d','e','f','g','h','i','j'});
        log(buffer);

        // 切片,切片过程中没有发送数据复制
        ByteBuf f1 = buffer.slice(0, 5);
        ByteBuf f2 = buffer.slice(5, 5);
        log(f1);
        log(f2);

        System.out.println("====================================");
        f1.setByte(0,'b');
        log(buffer);
        log(f1);
        log(f2);

    }

}
